package iscript.gameFramework.IsoLibarys.data 
{
	import flash.utils.Dictionary;
	import iscript.coreFramework.displays.Element;
	import iscript.coreFramework.util.GUID;
	import iscript.gameFramework.IsoLibarys.IsoScene;
	import iscript.gameFramework.IsoLibarys.IsoView;

	public class IsoViewList 
	{
		

		
		private var isoscene:IsoScene
		private var _data:Vector.<ViewListItem> = new Vector.<ViewListItem>();
		private var _isosceneList:Dictionary = new Dictionary();
	
		public function get count():int { return _data.length; }
		
		public function add(isoview:IsoView, key:String = null):void {
			   
			
			 _isosceneList[isoview] = key;
			 // if (getIsoView(isoscene, key)!=null) throw new Error("该isoscene中key:"+key+"已经存在.")   
			
 	  
			}
			
		 
			
			
		/**
		 * isoview Class  or  key String
		 * @param	isoscene
		 * @param	target
		 */	
		public function remove(isoscene:IsoScene, target:*):void {
			    if (target is IsoView) {
						 delete _isosceneList[target];
					}
			 
			}
			
		public function getIsoView(isoscene:IsoScene,key:String):IsoView {
			     for each( var item:ViewListItem in  _data) {
					     if (item.isoscene == isoscene && item.keyName == key) {
							 return item.isoview;
							 }
					 }
				  return null;
			}
		 
			
		/**
		 * isoview Class  or  key String
		 * @param	isoscene
		 * @param	key
		 */	
		public function activeIsoView(isoscene:IsoScene,  target:*):void {
			   var isoview:IsoView;
			   if(target is String)isoview= getIsoView(isoscene, key);
			   if (target is IsoView) isoview = target;
			   
			   for each (var item:ViewListItem  in _data) 
			   {
					if (item.isoscene == isoscene ) {
							   if (isoview == item.isoview) {
									   item.isActive = true;
									   Element.Active(item.isoview);
									   _isosceneList[isoscene] = item.isoview;
									   }else {
									   item.isActive = false;
									   Element.unActive(item.isoview);
									}
							  } 
					 }
			}
			
		public function getIsoViewKeyName(isoscene:IsoScene,isoview:IsoView):String {
			      for each (var item:ViewListItem  in _data) 
			      {
				    if (item.isoview==isoview && item.isoscene == isoscene) {
					      return item.keyName;
					 }
				  }
				  return null;
			}
			
		public function getActiveIsoView(isoscene:IsoScene):IsoView {
			  return  _isosceneList[isoscene];
			}
			
		public function clear():void {
			  _data = new Vector.<ViewListItem>();
			  _isosceneList = new Dictionary();
			}	
			
	}
}

